package com.zhoulu.service.system;

import com.zhoulu.domain.system.MenuVo;
import com.zhoulu.domain.system.SysMenu;
import com.zhoulu.mapper.system.SysMenuMapper;
import com.zhoulu.util.TreeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class SysMenuService {

    @Autowired
    private SysMenuMapper sysMenuMapper;

    public Map<String, Object> menu(String username) {
        Map<String, Object> map = new HashMap<>(16);
        Map<String,Object> home = new HashMap<>(16);
        Map<String,Object> logo = new HashMap<>(16);
        List<SysMenu> menuList = sysMenuMapper.findAllByStatusOrderBySort(username);
        List<MenuVo> menuInfo = new ArrayList<>();
        for (SysMenu e : menuList) {
            MenuVo menuVO = new MenuVo();
            menuVO.setId(e.getKey().getId());
            menuVO.setPid(e.getPid());
            menuVO.setHref(e.getKey().getHref());
            menuVO.setTitle(e.getKey().getTitle());
            menuVO.setIcon(e.getIcon());
            menuVO.setTarget(e.getTarget());
            menuInfo.add(menuVO);
        }
        map.put("menuInfo", TreeUtil.toTree(menuInfo, 0L));
        home.put("title","首页");
        home.put("href","page/welcome-1.html?t=1");//控制器路由,自行定义
        logo.put("title","图书管理系统");
        logo.put("image","images/logo.png");//静态资源文件路径,可使用默认的logo.png
        logo.put("href", "");
        map.put("homeInfo", home);
        map.put("logoInfo", logo);
        return map;
    }
}
